from django.db import models

# Create your models here.

class Classify(models.Model):
    name = models.CharField(max_length=50)
    def __str__(self):
        return self.name
    def having(self):
        res = Detail.objects.filter(Cid_id=self.id)
        Str = 'Null'
        for item in res:
            Str =Str + str(item) + '/'
        if Str == 'Null':
            return Str
        return Str[:-1]
    having.short_description = "having"

class Detail(models.Model):
    Cid = models.ForeignKey(Classify, on_delete=models.CASCADE)
    name = models.CharField(max_length=50)
    def __str__(self):
        return self.name
    def belong(self):
        return self.Cid
    belong.short_description = "belong_to"

class Content(models.Model):
    Did = models.ForeignKey(Detail, on_delete=models.CASCADE)
    user = models.CharField(max_length=20)
    time = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=20)
    text = models.CharField(max_length=500)
    status = models.BooleanField(default=0)

    def belong(self):
        return self.Did
    belong.short_description = "belong_to"

class Modification(models.Model):
    Cid = models.SmallIntegerField(default=0)
    text = models.CharField(max_length=500)
    status = models.BooleanField(default=0)
    check = models.BooleanField(default=0)

    def Status(self):
        if self.status == 0:
            return "WAITCONFIRM"
        else:
            return "CONFIRM"
